#include "sl698ph_720p.h"
#include "panels.h"

static void LCD_power_on(__u32 sel);
static void LCD_power_off(__u32 sel);
static void LCD_bl_open(__u32 sel);
static void LCD_bl_close(__u32 sel);

static void LCD_panel_init(__u32 sel);
static void LCD_panel_exit(__u32 sel);

static void LCD_cfg_panel_info(panel_extend_para * info)
{
	__u32 i = 0, j=0;
	__u32 items;
	__u8 lcd_gamma_tbl[][2] =
	{
		//{input value, corrected value}
		{0, 0},
		{15, 15},
		{30, 30},
		{45, 45},
		{60, 60},
		{75, 75},
		{90, 90},
		{105, 105},
		{120, 120},
		{135, 135},
		{150, 150},
		{165, 165},
		{180, 180},
		{195, 195},
		{210, 210},
		{225, 225},
		{240, 240},
		{255, 255},
	};

	__u8 lcd_bright_curve_tbl[][2] =
	{
		//{input value, corrected value}
		{0    ,0 },//0
		{1   ,50 },//0
		{30   ,50  },//0
		{45   ,50 },// 1
		{60   ,50  },// 2
		{75   ,50  },// 5
		{90   ,50  },//9
		{105   ,50 }, //15
		{120  ,50 },//23
		{135  ,50 },//33
		{150  ,54 },
		{165  ,67 },
		{180  ,84 },
		{195  ,108},
		{210  ,137},
		{225 ,171},
		{240 ,210},
		{255 ,255},
	};

	__u32 lcd_cmap_tbl[2][3][4] = {
	{
		{LCD_CMAP_G0,LCD_CMAP_B1,LCD_CMAP_G2,LCD_CMAP_B3},
		{LCD_CMAP_B0,LCD_CMAP_R1,LCD_CMAP_B2,LCD_CMAP_R3},
		{LCD_CMAP_R0,LCD_CMAP_G1,LCD_CMAP_R2,LCD_CMAP_G3},
		},
		{
		{LCD_CMAP_B3,LCD_CMAP_G2,LCD_CMAP_B1,LCD_CMAP_G0},
		{LCD_CMAP_R3,LCD_CMAP_B2,LCD_CMAP_R1,LCD_CMAP_B0},
		{LCD_CMAP_G3,LCD_CMAP_R2,LCD_CMAP_G1,LCD_CMAP_R0},
		},
	};

	memset(info,0,sizeof(panel_extend_para));

	items = sizeof(lcd_gamma_tbl)/2;
	for(i=0; i<items-1; i++) {
		__u32 num = lcd_gamma_tbl[i+1][0] - lcd_gamma_tbl[i][0];

		for(j=0; j<num; j++) {
			__u32 value = 0;

			value = lcd_gamma_tbl[i][1] + ((lcd_gamma_tbl[i+1][1] - lcd_gamma_tbl[i][1]) * j)/num;
			info->lcd_gamma_tbl[lcd_gamma_tbl[i][0] + j] = (value<<16) + (value<<8) + value;
		}
	}
	info->lcd_gamma_tbl[255] = (lcd_gamma_tbl[items-1][1]<<16) + (lcd_gamma_tbl[items-1][1]<<8) + lcd_gamma_tbl[items-1][1];

	items = sizeof(lcd_bright_curve_tbl)/2;
	for(i=0; i<items-1; i++) {
		__u32 num = lcd_bright_curve_tbl[i+1][0] - lcd_bright_curve_tbl[i][0];

		for(j=0; j<num; j++) {
			__u32 value = 0;

			value = lcd_bright_curve_tbl[i][1] + ((lcd_bright_curve_tbl[i+1][1] - lcd_bright_curve_tbl[i][1]) * j)/num;
			info->lcd_bright_curve_tbl[lcd_bright_curve_tbl[i][0] + j] = value;
		}
	}
	info->lcd_bright_curve_tbl[255] = lcd_bright_curve_tbl[items-1][1];

	memcpy(info->lcd_cmap_tbl, lcd_cmap_tbl, sizeof(lcd_cmap_tbl));

}

static __s32 LCD_open_flow(__u32 sel)
{
	LCD_OPEN_FUNC(sel, LCD_power_on, 30);   //open lcd power, and delay 50ms
	LCD_OPEN_FUNC(sel, LCD_panel_init, 10);   //open lcd power, than delay 200ms
	LCD_OPEN_FUNC(sel, sunxi_lcd_tcon_enable, 100);     //open lcd controller, and delay 100ms
	LCD_OPEN_FUNC(sel, LCD_bl_open, 0);     //open lcd backlight, and delay 0ms

	return 0;
}

static __s32 LCD_close_flow(__u32 sel)
{
	LCD_CLOSE_FUNC(sel, LCD_bl_close, 0);       //close lcd backlight, and delay 0ms
	LCD_CLOSE_FUNC(sel, sunxi_lcd_tcon_disable, 0);         //close lcd controller, and delay 0ms
	LCD_CLOSE_FUNC(sel, LCD_panel_exit,	20);   //open lcd power, than delay 200ms
	LCD_CLOSE_FUNC(sel, LCD_power_off, 50);   //close lcd power, and delay 500ms

	return 0;
}

static void LCD_power_on(__u32 sel)
{
    printf("mb709 %s", __func__);
	sunxi_lcd_power_enable(sel, 0);//config lcd_power pin to open lcd power0
//	sunxi_lcd_pwm_enable(sel);//open pwm module
}

static void LCD_power_off(__u32 sel)
{
    printf("mb709 %s", __func__);
	sunxi_lcd_pin_cfg(sel, 0);
	sunxi_lcd_power_disable(sel, 0);//config lcd_power pin to close lcd power0
//	sunxi_lcd_pwm_disable(sel);//close pwm module
}

static void LCD_bl_open(__u32 sel)
{
    printf("mb709 %s", __func__);
	sunxi_lcd_pwm_enable(sel);//open pwm module
	sunxi_lcd_backlight_enable(sel);//config lcd_bl_en pin to open lcd backlight
}

static void LCD_bl_close(__u32 sel)
{
    printf("mb709 %s", __func__);
	sunxi_lcd_backlight_disable(sel);//config lcd_bl_en pin to close lcd backlight
	sunxi_lcd_pwm_disable(sel);//close pwm module
}
#if 1

#define REGFLAG_DELAY             							0XFF
#define REGFLAG_END_OF_TABLE      						0xFE   // END OF REGISTERS MARKER

struct LCM_setting_table {
    __u8 cmd;
    __u32 count;
    __u8 para_list[64];
};

#if 0
static struct LCM_setting_table lcm_initialization_setting[] = {
	
	/*
	Note :

	Data ID will depends on the following rule.
	
		count of parameters > 1	=> Data ID = 0x39
		count of parameters = 1	=> Data ID = 0x15
		count of parameters = 0	=> Data ID = 0x05

	Structure Format :

	{DCS command, count of parameters, {parameter list}}
	{REGFLAG_DELAY, milliseconds of time, {}},

	...

	Setting ending by predefined flag
	
	{REGFLAG_END_OF_TABLE, 0x00, {}}
	*/
#if 0
	#if 1
	{0x11,	0,	{}},     //sleep out
	{REGFLAG_DELAY, 150, {}},

	{0xB0,	  1,  {0x00}},	  // 
	{REGFLAG_DELAY, 10, {}},

	{0xBA,	  1,  {0xA7}},	  // 

	{0xBD,	  1,  {0x38}},	
	{0xBE,	  1,  {0xAA}},
	{0xBF,	  1,  {0x1F}},
	{0xC0,	  1,  {0x0C}},	 
	{0xC2,	  1,  {0x2A}},	 
	{0xC3,	  1,  {0x34}},	 
	{0xC4,	  1,  {0x73}},	 
	{0xC5,	  1,  {0x14}},	   

	{0xC6,	  1,  {0x02}},	   

	{0xC7,	  1,  {0x14}},	   

	{0xC8,	  1,  {0x02}},	   

	{0xC9,	  1,  {0x06}},	   

	{0xB0,	  1,  {0x05}},	

	{0xBC,	  1,  {0xA0}},
	
	{REGFLAG_DELAY, 100, {}},

	{0xB0,	  1,  {0x01}},	
	{0xB1,	  1,  {0x5D}},	
	{0xB2,	  1,  {0x78}},	
	{0xB3,	  1,  {0xB1}},	
	{0xB4,	  1,  {0xDF}},	
	{0xB5,	  1,  {0x01}},	
	{0xB6,	  1,  {0x68}},	
	{0xB7,	  1,  {0xA3}},	
	{0xB8,	  1,  {0xCF}},	
	{0xB9,	  1,  {0x07}},	
	{0xBA,	  1,  {0x2C}},	
	{0xBB,	  1,  {0x58}},	
	{0xBC,	  1,  {0x80}},	
	{0xBD,	  1,  {0xAC}},	
	{0xBE,	  1,  {0xCA}},	
	{0xBF,	  1,  {0xF3}},	
	

	{0xC0,	  1,  {0x24}},	   

	{0xC1,	  1,  {0xE4}},	
	{0xC2,	  1,  {0x00}},
	{0xC3,	  1,  {0x55}},
	{0xC4,	  1,  {0xAA}},
	{0xC5,	  1,  {0xAB}},
	{0xC6,	  1,  {0x03}},
	{0xC7,	  1,  {0x5D}},
	

	{0xC8,	  1,  {0X78}},	   

	{0xC9,	  1,  {0xB1}},	   

	{0xCA,	  1,  {0xDF}},	   

	{0xCB,	  1,  {0x01}},	   

	{0xCC,	  1,  {0x68}},	   

	{0xCD,	  1,  {0xA3}},	
	{0xCE,	  1,  {0xCF}},
	{0xCF,	  1,  {0x07}},
	
	{REGFLAG_DELAY, 10, {}},
	{0xD0,	  1,  {0x2C}},	
	{0xD1,	  1,  {0x58}},	
	{0xD2,	  1,  {0x80}},	
	{0xD3,	  1,  {0xAC}},	
	{0xD4,	  1,  {0xCA}},	
	{0xD5,	  1,  {0xF3}},	
	{0xD6,	  1,  {0x24}},	
	{0xD7,	  1,  {0xE4}},	
	{0xD8,	  1,  {0x00}},	
	{0xD9,	  1,  {0x55}},	
	{0xDA,	  1,  {0xAA}},	
	{0xDB,	  1,  {0xAB}},	
	{0xDC,	  1,  {0x03}},	   

	{0xDD,	  1,  {0x5D}},	
	
	{0xDE,	  1,  {0x78}},	   

	{0xDF,	  1,  {0xB1}},	
	
	{REGFLAG_DELAY, 10, {}},

	{0xE0,	  1,  {0xDF}},	   

	{0xE1,	  1,  {0x01}},	   

	{0xE2,	  1,  {0x68}},	   

	{0xE3,	  1,  {0xA3}},	   

	{0xE4,	  1,  {0xCF}},	   

	{0xE5,	  1,  {0x07}},	   

	{0xE6,	  1,  {0x2C}},	   

	{0xE7,	  1,  {0x58}},	   

	{0xE8,	  1,  {0x80}},	 

	{0xE9,	  1,  {0xAC}},	   

	{0xEA,	  1,  {0xCA}},	   

	{0xEB,	  1,  {0xF3}},	   

	{0xEC,	  1,  {0x24}},	   

	{0xED,	  1,  {0xE4}},	   

	{0xEE,	  1,  {0x00}},	   

	{0xEF,	  1,  {0x55}},	
	
	{REGFLAG_DELAY, 10, {}},

	{0xF0,	  1,  {0xAA}},
	
	{0xF1,	  1,  {0xAB}},	   

	{0xF2,	  1,  {0x03}},	   


	{0xB0,	  1,  {0x03}},	
	{0xC0,	  1,  {0x49}},	
	{0xC1,	  1,  {0x10}},
	{0xC2,	  1,  {0x28}},
	{0xC3,	  1,  {0x01}},
	{0xC4,	  1,  {0x28}},
	{0xC5,	  1,  {0x01}},
	{0xC8,	  1,  {0x42}},
	{0xC9,	  1,  {0x40}},
	{0xCA,	  1,  {0x01}},
	{0xCB,	  1,  {0x00}},
	{0xCC,	  1,  {0x02}},
	{0xCD,	  1,  {0x08}},
	{0xCE,	  1,  {0x09}},
	
	{0xD0,	  1,  {0x03}},	
	{0xD1,	  1,  {0x0A}},	
	{0xDC,	  1,  {0x00}},	
	{0xDD,	  1,  {0x00}},	
	{0xDE,	  1,  {0x00}},
	{0xDF,	  1,  {0x00}},
	
	{0xE0,	  1,  {0x12}},	
	{0xE1,	  1,  {0x11}},
	{0xE2,	  1,  {0x05}},
	{0xE3,	  1,  {0x06}},
	{0xE4,	  1,  {0x07}},
	{0xE5,	  1,  {0x08}},
	{0xE6,	  1,  {0x09}},
	{0xE7,	  1,  {0x0A}},
	{0xE8,	  1,  {0x0B}},
	{0xE9,	  1,  {0x0C}},
	{0xEA,	  1,  {0x02}},
	{0xEB,	  1,  {0x01}},
	{0xEC,	  1,  {0x12}},
	{0xED,	  1,  {0x11}},
	{0xEE,	  1,  {0x05}},
	{0xEF,	  1,  {0x06}},
	
	{0xF0,	  1,  {0x07}},	
	{0xF1,	  1,  {0x08}},	
	{0xF2,	  1,  {0x09}},	
	{0xF3,	  1,  {0x0A}},	
	{0xF4,	  1,  {0x0B}},	
	{0xF5,	  1,  {0x0C}},	
	{0xF6,	  1,  {0x02}},	
	{0xF7,	  1,  {0x01}},	
	{0xF8,	  1,  {0x00}},	
	{0xF9,	  1,  {0x00}},	
	{0xFA,	  1,  {0x00}},	
	{0xFB,	  1,  {0x00}},	

	{0xB0,	  1,  {0x05}},	
	{0xB3,	  1,  {0x52}},
	
	{0xB0,	  1,  {0x06}},
	{0xB8,	  1,  {0xA5}},
	{0xC0,	  1,  {0xA5}},
	{0xCE,	  1,  {0x4F}},
	{0xC7,	  1,  {0x1F}},
	{0xCC,	  1,  {0x1F}},

	{0xB0,	  1,  {0x03}},	
	{0xB2,	  1,  {0xA5}},	
	{0xB3,	  1,  {0x04}},	
	

	{0x11,	  1,  {0x00}},	   
	{REGFLAG_DELAY, 150, {}},

	{0x29,	0,	{0x00}},
	{REGFLAG_DELAY, 150, {}},
	// Note
	// Strongly recommend not to set Sleep out / Display On here. That will cause messed frame to be shown as later the backlight is on.


	// Setting ending by predefined flag
	{REGFLAG_END_OF_TABLE, 0x00, {}}
	#else	
	{0x11,	0,	{}},     //sleep out
	{REGFLAG_DELAY, 150, {}},

	{0xB0,	  1,  {0x00}},	  // 
	{REGFLAG_DELAY, 10, {}},

	{0xBA,	  1,  {0xA5}},	  // 

	{0xBD,	  1,  {0x5F}},	   

	{0xC5,	  1,  {0x00}},	   

	{0xC6,	  1,  {0x02}},	   

	{0xC7,	  1,  {0x03}},	   

	{0xC8,	  1,  {0x03}},	   

	{0xC9,	  1,  {0x06}},	   

	{0xB0,	  1,  {0x03}},	   

	{0xC0,	  1,  {0x40}},	   

	{0xC1,	  1,  {0x10}},	   

	{0xC8,	  1,  {0X41}},	   

	{0xC9,	  1,  {0x61}},	   

	{0xCA,	  1,  {0x04}},	   

	{0xC5,	  1,  {0xA1}},	   

	{0xC4,	  1,  {0x23}},	   

	{0xCB,	  1,  {0x0F}},	
	
	{REGFLAG_DELAY, 10, {}},

	{0xDC,	  1,  {0x01}},	   

	{0xDD,	  1,  {0x07}},	
	
	{0xDE,	  1,  {0x05}},	   

	{0xDF,	  1,  {0x00}},	
	
	{REGFLAG_DELAY, 10, {}},

	{0xE0,	  1,  {0x00}},	   

	{0xE1,	  1,  {0x00}},	   

	{0xE2,	  1,  {0x00}},	   

	{0xE3,	  1,  {0x00}},	   

	{0xE4,	  1,  {0x00}},	   

	{0xE5,	  1,  {0x00}},	   

	{0xE6,	  1,  {0x00}},	   

	{0xE7,	  1,  {0x00}},	   

	{0xE8,	  1,  {0x00}},	 

	{0xE9,	  1,  {0x00}},	   

	{0xEA,	  1,  {0x00}},	   

	{0xEB,	  1,  {0x00}},	   

	{0xEC,	  1,  {0x02}},	   

	{0xED,	  1,  {0x08}},	   

	{0xEE,	  1,  {0x06}},	   

	{0xEF,	  1,  {0x00}},	
	
	{REGFLAG_DELAY, 10, {}},

	{0xF0,	  1,  {0x00}},
	
	{0xF1,	  1,  {0x00}},	   

	{0xF2,	  1,  {0x00}},	   

	{0xF3,	  1,  {0x00}},	   

	{0xF4,	  1,  {0x00}},	   

	{0xF5,	  1,  {0x00}},	   

	{0xF6,	  1,  {0x00}},	   

	{0xF7,	  1,  {0x00}},	   

	{0xF8,	  1,  {0x00}},	   

	{0xF9,	  1,  {0x00}},	   

	{0xFA,	  1,  {0x00}},	   

	{0xFB,	  1,  {0x00}},	   
	{REGFLAG_DELAY, 10, {}},

	{0xB0,	  1,  {0x05}},	   

	{0xB3,	  1,  {0x52}},	   // 0x52

	{0xB8,	  1,  {0xA5}},	   
	{REGFLAG_DELAY, 10, {}},

	{0xC0,	  1,  {0xA5}},	   

	{0xC7,	  1,  {0x1F}},	   

	{0xCE,	  1,  {0x4F}},	   

	{0x11,	  1,  {0x00}},	   
	{REGFLAG_DELAY, 150, {}},

	{0x29,	0,	{0x00}},
	{REGFLAG_DELAY, 150, {}},
	// Note
	// Strongly recommend not to set Sleep out / Display On here. That will cause messed frame to be shown as later the backlight is on.


	// Setting ending by predefined flag
	{REGFLAG_END_OF_TABLE, 0x00, {}}
	#endif
	#endif
	{0x00,	  1,  {0x00}},	   
	{0xFF,	  3,  {0x12,0x83,0x01}},	   
	{0x00,	  1,  {0x80}},	   
	{0xFF,	  2,  {0x12,0x83}},	   
	{0x00,	  1,  {0x80}},	   
	{0xC0,	  9,  {0x00,0x64,0x00,0x10,0x10,0x00,0x64,0x10,0x10}},	   
	{0x00,	  1,  {0x90}},	   
	{0xC0,	  6,  {0x00,0x56,0x00,0x01,0x00,0x04}},	   
	{0x00,	  1,  {0xA4}},	   
	{0xC0,	  1,  {0x16}},	   
	{0x00,	  1,  {0xB3}},	   
	{0xC0,	  2,  {0x00,0x50}},	   
	{0x00,	  1,  {0x81}},	   
	{0xC1,	  1,  {0x66}},	   
	{0x00,	  1,  {0x90}},	   
	{0xC4,	  1,  {0x49}},	   
	{0x00,	  1,  {0xA0}},	   
	{0xC4,	  14,  {0x05,0x10,0x06,0x02,0x05,0x15,0x10,0x05,0x10,0x07,0x02,0x05,0x15,0x10}},	   
	{0x00,	  1,  {0xB0}},	   
	{0xC4,	  2,  {0x00,0x00}},	   
	{0x00,	  1,  {0x91}},	   
	{0xC5,	  3,  {0x46,0x40,0x00}},	   
	{0x00,	  1,  {0x00}},	   
	{0xD8,	  2,  {0xCF,0xCF}},	   
	{0x00,	  1,  {0x00}},	   
	{0xd9,	  1,  {0x47}},
	{0x00,	  1,  {0x81}},	   
	{0xC4,	  1,  {0x82}},	   
	{0x00,	  1,  {0xB0}},	   
	{0xC5,	  2,  {0x04,0xB8}},	   
	{0x00,	  1,  {0xBB}},	   
	{0xC5,	  1,  {0x80}},	   
	{0x00,	  1,  {0x82}},	   
	{0xC4,	  1,  {0x02}},	   
	{0x00,	  1,  {0xC6}},	   
	{0xB0,	  1,  {0x03}},	   
	{0x00,	  1,  {0x00}},	   
	{0xD0,	  1,  {0x40}},	   
	{0x00,	  1,  {0x00}},	   
	{0xD1,	  2,  {0x00,0x00}},	   
	{0x00,	  1,  {0x80}},	   
	{0xCB,	  11,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},	   
	{0x00,	  1,  {0x90}},	   
	{0xCB,	  15,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},	   
	{0x00,	  1,  {0xA0}},	   
	{0xCB,	  15,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},	   
	{0x00,	  1,  {0xB0}},	   
	{0xCB,	  15,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},	   
	{0x00,	  1,  {0xC0}},	   
	{0xCB,	  15,  {0x05,0x05,0x05,0x05,0x05,0x05,0x00,0x00,0x00,0x00,0x05,0x05,0x00,0x05,0x05}},	   
	{0x00,	  1,  {0xD0}},	   
	{0xCB,	  15,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x05,0x05,0x05,0x05,0x05,0x00,0x00}},	   
	{0x00,	  1,  {0xE0}},	   
	{0xCB,	  14,  {0x00,0x00,0x05,0x05,0x00,0x05,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},	   
	{0x00,	  1,  {0xF0}},	   
	{0xCB,	  11,  {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}},	   
	{0x00,	  1,  {0x80}},	   
	{0xCC,	  15,  {0x0E,0x10,0x0A,0x0C,0x02,0x04,0x00,0x00,0x00,0x00,0x2E,0x2D,0x00,0x29,0x2A}},	   
	{0x00,	  1,  {0x90}},	   
	{0xCC,	  15,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0x0F,0x09,0x0B,0x01,0x03,0x00,0x00}},	
	{0x00,	  1,  {0xA0}},
	{0xCC,	  14,  {0x00,0x00,0x2E,0x2D,0x00,0x29,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
	{0x00,	  1,  {0xB0}},
	{0xCC,	  15,  {0x0B,0x09,0x0F,0x0D,0x03,0x01,0x00,0x00,0x00,0x00,0x2D,0x2E,0x00,0x29,0x2A}},
	{0x00,	  1,  {0xC0}},
	{0xCC,	  15,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0A,0x10,0x0E,0x04,0x02,0x00,0X00}},
	{0x00,	  1,  {0xD0}},
	{0xCC,	  14,  {0x00,0x00,0x2D,0x2E,0x00,0x29,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
	{0x00,	  1,  {0x80}},
	{0xCE,	  12,  {0x8B,0x03,0x18,0x8A,0x03,0x18,0x89,0x03,0x18,0x88,0x03,0x18}},
	{0x00,	  1,  {0x90}},
	{0xCE,	  14,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
	{0x00,	  1,  {0xA0}},
	{0xCE,	  14,  {0x38,0x07,0x05,0x00,0x00,0x18,0x00,0x38,0x06,0x05,0x01,0x00,0x18,0x00}},
	{0x00,	  1,  {0xB0}},
	{0xCE,	  14,  {0x38,0x05,0x05,0x02,0x00,0x18,0x00,0x38,0x04,0x05,0x03,0x00,0x18,0x00}},
	{0x00,	  1,  {0xC0}},
	{0xCE,	  14,  {0x38,0x03,0x05,0x04,0x00,0x18,0x00,0x38,0x02,0x05,0x05,0x00,0x18,0x00}},
	{0x00,	  1,  {0xD0}},
	{0xCE,	  14,  {0x38,0x01,0x05,0x06,0x00,0x18,0x00,0x38,0x00,0x05,0x07,0x00,0x18,0x00}},
	{0x00,	  1,  {0x80}},
	{0xCF,	  14,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
	{0x00,	  1,  {0x90}},
	{0xCF,	  14,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
	{0x00,	  1,  {0xA0}},
	{0xCF,	  14,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
	{0x00,	  1,  {0xB0}},
	{0xCF,	  14,  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
	{0x00,	  1,  {0xC0}},
	{0xCF,	  11,  {0x3D,0x02,0x15,0x20,0x00,0x00,0x01,0x81,0x00,0x03,0x08}},
	{0x00,	  1,  {0xB5}},
	{0xC5,	  6,  {0x00,0x6F,0xFF,0x00,0x6F,0xFF}},
	{0x00,	  1,  {0x90}},
	{0xF5,	  4,  {0x02,0x11,0x02,0x11}},
	{0x00,	  1,  {0x90}},
	{0xC5,	  1,  {0x50}},
	{0x00,	  1,  {0x94}},
	{0xC5,	  1,  {0x66}},
	{0x00,	  1,  {0xB2}},
	{0xF5,	  2,  {0x00,0x00}},
	{0x00,	  1,  {0xB4}},
	{0xF5,	  2,  {0x00,0x00}},
	{0x00,	  1,  {0xB6}},
	{0xF5,	  2,  {0x00,0x00}},
	{0x00,	  1,  {0xB8}},
	{0xF5,	  2,  {0x00,0x00}},
	{0x00,	  1,  {0x94}},
	{0xF5,	  1,  {0x02}},
	{0x00,	  1,  {0xBA}},
	{0xF5,	  1,  {0x03}},
	{0x00,	  1,  {0xB4}},
	{0xC5,	  1,  {0xC0}},
	{0x00,	  1,  {0x00}},
	{0xE1,	  16,  {0x00,0x0C,0x12,0x0F,0x08,0x10,0x0b,0x0A,0x04,0x07,0x0D,0x07,0x0E,0x15,0x10,0x03}},
	{0x00,	  1,  {0x00}},
	{0xE2,	  16, {0x00,0x0C,0x12,0x0E,0x07,0x10,0x0b,0x09,0x04,0x07,0x0D,0x07,0x0E,0x15,0x10,0x03}},
	{0x00,	  1,  {0xB4}},
	{0xC0,	  1,  {0x55}},
	{0x00,	  1,  {0xA0}},
	{0xC1,	  1,  {0x02}},
	{0x00,	  1,  {0x81}},
	{0xC1,	  1,  {0x07}},
	
	{0x00,	  1,  {0xb5}},//modify @20140423
	{0xC0,	  1,  {0x48}},//modify @20140423
	
	{0x00,	  1,  {0x00}},
	{0xff,	  3,  {0xff,0xff,0xff}},
	{REGFLAG_DELAY, 20, {}},
	{0x00,	  1,  {0x00}},
	{0x11,	  1,  {0x00}},
	{REGFLAG_DELAY, 120, {}},
	{0x00,	  1,  {0x00}},
	{0x29,	  1,  {0x00}},
	{REGFLAG_DELAY, 100, {}},
	{REGFLAG_END_OF_TABLE, 0x00, {}}
	
};
#endif
static struct LCM_setting_table lcm_initialization_setting[] = {
#if 0    
 {0xf0, 2,{0x5a, 0x5a }},
 {0xf1, 2,{0x5a, 0x5a }},
 {0xfc, 2,{0xa5, 0xa5 }},
 {0xd0, 2,{0x00, 0x10 }},
 {0xc3, 3,{0x40, 0x00, 0x28 }},
 {REGFLAG_DELAY,20,{}},
 {0x36, 1,{0x04 }},
 {0xf6, 6,{0x63, 0x20, 0x86, 0x00, 0x00, 0x10 }},
 {0x11,0,{0x00}},
 {REGFLAG_DELAY,120,{}}, 
 {0x36, 1,{0x00 }},
 {0xf0, 2,{0xa5, 0xa5 }},
 {0xf1, 2,{0xa5, 0xa5 }},
 {0xfc, 2,{0x5a, 0x5a }},
 {0x29,0,{0x00}},
 {REGFLAG_DELAY,200,{}},
 {REGFLAG_END_OF_TABLE, 0x00, {}}
#endif
//#if 0	
//	{0x25,1,{0x55}},
//	{0xB1,1,{0x08}},
//	{0xB2,1,{0x40}},

	//{0x01,0,{0x00}},
	//{REGFLAG_DELAY,30,{}},

	{0x80,1,{0x58}},
	{0x81,1,{0x47}},
	{0x82,1,{0xD4}},
	{0x83,1,{0x88}},
	{0x84,1,{0xA9}},
	{0x85,1,{0xC3}},
	{0x86,1,{0x82}},
//#endif
 
 {REGFLAG_END_OF_TABLE, 0x00, {}}
};
#endif



static void LCD_panel_init(__u32 sel)
{
	__u32 i;

    printf("mb709 %s", __func__);

	sunxi_lcd_pin_cfg(sel, 1);
	sunxi_lcd_delay_ms(10);

	panel_rst(1);	 //add by lyp@20140423
	sunxi_lcd_delay_ms(50);//add by lyp@20140423
	panel_rst(0);
	sunxi_lcd_delay_ms(20);
	panel_rst(1);
	sunxi_lcd_delay_ms(200);

	for(i=0;;i++)
	{
		if(lcm_initialization_setting[i].cmd == REGFLAG_END_OF_TABLE)
			break;
		else if (lcm_initialization_setting[i].cmd == REGFLAG_DELAY)
			sunxi_lcd_delay_ms(lcm_initialization_setting[i].count);
		else
		{
			printf("[mb709_mipi] send cmd=0x%x\n", lcm_initialization_setting[i].cmd);
			dsi_dcs_wr(0,lcm_initialization_setting[i].cmd,lcm_initialization_setting[i].para_list,lcm_initialization_setting[i].count);
		}
	}

	//sunxi_lcd_dsi_write(sel,DSI_DCS_EXIT_SLEEP_MODE, 0, 0);
	//sunxi_lcd_delay_ms(200);

	sunxi_lcd_dsi_clk_enable(sel);

	//sunxi_lcd_dsi_write(sel,DSI_DCS_SET_DISPLAY_ON, 0, 0);
	//sunxi_lcd_delay_ms(200);
	
	return;
}

static void LCD_panel_exit(__u32 sel)
{
    printf("mb709 %s", __func__);
	sunxi_lcd_dsi_clk_disable(sel);
	panel_rst(0);
	return ;
}

//sel: 0:lcd0; 1:lcd1
static __s32 LCD_user_defined_func(__u32 sel, __u32 para1, __u32 para2, __u32 para3)
{
	return 0;
}

__lcd_panel_t mb709_mipi_panel = {
	/* panel driver name, must mach the name of lcd_drv_name in sys_config.fex */
	.name = "mb709_mipi",
	.func = {
		.cfg_panel_info = LCD_cfg_panel_info,
		.cfg_open_flow = LCD_open_flow,
		.cfg_close_flow = LCD_close_flow,
		.lcd_user_defined_func = LCD_user_defined_func,
	},
};
